package problem118;

import java.util.ArrayList;
import java.util.List;

//118.杨辉三角
//https://leetcode.cn/problems/pascals-triangle/?envType=study-plan-v2&envId=top-100-liked

class Solution {
    public List<List<Integer>> generate(int n) {
        List<List<Integer>> list = new ArrayList<>();
        for(int i = 0; i<n; i++) {
            List<Integer> t = new ArrayList<>();
            for(int j = 0; j<=i; j++) {
                if(i == 0 || j == 0 || j == i) {
                    t.add(1);
                }else {
                    int s = list.get(i-1).get(j-1) + list.get(i-1).get(j);
                    t.add(s);
                }
            }
            list.add(t);
        }
        return list;
    }
}